using System;
using System.Collections.Generic;
using System.Web.UI;
using com.cruxomatic.controllers;
using com.cruxomatic.controllers.Administration;
using com.cruxomatic.DTOs.Configuration;
using com.cruxomatic.views.Enums;
using com.cruxomatic.views;
using System.Web.UI.WebControls;
using System.Linq;
using com.cruxomatic.DTOs;
using com.cruxomatic.controllers;
using com.cruxomatic.views;


public partial class Administration_MasterLocations : BaseView, IMasterLocation
{
    private  MasterLocationController _controller;

    protected void Page_Load(object sender, EventArgs e)
    {
        _controller = new MasterLocationController(this);
        _controller.InitView(Page.IsPostBack);
    }

    public void grdMasterLocation_RowCommand(object sender, CommandEventArgs e)
    {
        RowCommands rowCommand = (RowCommands)Enum.Parse(typeof(RowCommands), e.CommandName);
        if (rowCommand == RowCommands.EditItem)
            _controller.OpenDetail(int.Parse((string)e.CommandArgument));
        else if (rowCommand == RowCommands.DeleteItem)
            _controller.DeleteMasterLocation(int.Parse((string)e.CommandArgument));
    }

    protected void  grdMasterLocation_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ImageButton deleteButton = (ImageButton)e.Row.FindControl("btnItemDelete");
            string ReplaceConfirmation ="Are you sure to delete this record";
            deleteButton.Attributes.Add("onclick", "javascript:return "
                + "confirm('" + ReplaceConfirmation + "')");
         }
     }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        _controller.OpenList();
    }

    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        _controller.OpenDetail(0);
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        _controller.SaveData();
    }

	protected void btnBack_Click(object sender, EventArgs e)
    {
        _controller.RedirectToPreviousPage();
    }
     

    public  List<MasterLocationInformation> AllMasterLocation 
    {
        get
        {
            return (List< MasterLocationInformation>) grdMasterLocation.DataSource;
        }

        set
        {
            grdMasterLocation.DataSource = value;
            grdMasterLocation.DataBind();
        }
         
     }

    public  MasterLocationInformation  CurrentMasterLocation 
    {
        get
        {
            MasterLocationInformation  info = new  MasterLocationInformation();
            
info.MasterLocationID = int.Parse(lblMasterLocationIDValue.Text) ; 
info.LocationCode = txtLocationCode.Text ; 
info.LocationName = txtLocationName.Text ; 
info.LocationDescription = txtLocationDescription.Text ;   
             return  info ;
        }

        set
        {
          
lblMasterLocationIDValue.Text = value.MasterLocationID.ToString(); 
txtLocationCode.Text = value.LocationCode; 
txtLocationName.Text = value.LocationName; 
txtLocationDescription.Text = value.LocationDescription; 
        }
 

    }



    public ErrorInformation ErrorDetails
    {
        get
        {
            return pnlError.ErrorInformation;
        }
        set
        {
            pnlError.ErrorInformation = value;
        }
    }

    public FormMode FormMode
    {
        get
        {
            if (pnlAddEdit.Visible)
                return FormMode.AddEdit;
            else
                return FormMode.List;
        }
        set
        {
            if (value == FormMode.AddEdit)
            {
                pnlAddEdit.Visible = true;
                pnlList.Visible = false;
            }
            else
            {
                pnlAddEdit.Visible = false;
                pnlList.Visible = true;
            }
        }
    }
	
 	

}